package xonmp.hellowebview;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class HelloWebViewActivity extends Activity {
	
	private static final String TAG = "hello web view 2";
	private WebView mWebView;
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Log.i(TAG, "onCreate");
        mWebView = (WebView) findViewById(R.id.webview);
        mWebView.getSettings().setJavaScriptEnabled(true);
        mWebView.getSettings().setBuiltInZoomControls(true);
        mWebView.getSettings().setSupportZoom(true);
        mWebView.loadUrl("http://www.tacoma.washington.edu/tech/");
        mWebView.setWebViewClient(new HelloWebViewClient());
    }
    
    private class HelloWebViewClient extends WebViewClient {
    	@Override
    	public boolean shouldOverrideUrlLoading(WebView webview, String url)
    	{
    		webview.loadUrl(url);
    		return true;
    	}
    }
    
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event)
    {
    	if ((keyCode == KeyEvent.KEYCODE_BACK) && mWebView.canGoBack())
    	{
    		mWebView.goBack();
    		return true;
    	}
    	return super.onKeyDown(keyCode, event);
    }
    
    @Override
    protected void onStart()
    {
    	super.onStart();
    	Log.i(TAG, "onStart");
    }
    
    @Override
    protected void onRestart()
    {
    	super.onRestart();
    	Log.i(TAG, "onRestart");
    }
    
    @Override
    protected void onPause()
    {
    	super.onPause();
    	Log.i(TAG, "onPause");
    }
    
    @Override
    protected void onResume()
    {
    	super.onResume();
    	Log.i(TAG, "onResume");
    }
    
    @Override
    protected void onDestroy()
    {
    	super.onDestroy();
    	Log.i(TAG, "onDestroy");
    }
    
    @Override
    protected void onStop()
    {
    	super.onStop();
    	Log.i(TAG, "onStop");
    }
    
    @Override
    protected void onSaveInstanceState(Bundle outState)
    {
    	super.onSaveInstanceState(outState);
    	mWebView.saveState(outState);
    	Log.i(TAG, "onSaveInstanceState");
    }
    
    @Override
    protected void onRestoreInstanceState(Bundle savedInstanceState)
    {
    	super.onRestoreInstanceState(savedInstanceState);
    	mWebView.restoreState(savedInstanceState);
    	Log.i(TAG, "onRestoreInstanceState");
    }
}